﻿using SuperSocket.ProtoBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SuperWeight
{
    /// <summary>
    /// 数据接收协议
    /// <para>当前使用固定结束符【0D 0A】接收协议</para>
    /// </summary>
    public class WeightReceiveFilter : TerminatorReceiveFilter<WeightPackageInfo>
    {
        /// <summary>
        /// 构造函数
        /// <para>{0D 0A}十六进制转十进制{13,10}</para>
        /// </summary>
        public WeightReceiveFilter() : base(Encoding.ASCII.GetBytes("\r\n"))
        {
        }

        public override WeightPackageInfo ResolvePackage(IBufferStream bufferStream)
        {
            var Temp_Bytes = new byte[22];

            if (bufferStream.Length != 22)
            {
                bufferStream.Clear();
                return null;
            }

            var ReadCount = bufferStream.Read(Temp_Bytes, 0, Temp_Bytes.Length);
            if (ReadCount == 22)
            {
                return new WeightPackageInfo(Temp_Bytes, Encoding.ASCII);
            }
            return null;
        }


        // other code you need implement according yoru protocol details
    }
}
